package com.gst.cloudygovernance.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gst.cloudygovernance.R;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by YBH on 2017/12/18.
 */

public class ReportFragmentAdapter extends BaseAdapter {
    private Context mContext;
    //图片数组
    private Integer[] imgs = {R.mipmap.icon_31, R.mipmap.icon_32,
            R.mipmap.icon_33, R.mipmap.icon_34, R.mipmap.icon_35,
            R.mipmap.icon_36
    };
    //文字数组
    private String[] strings = new String[]{"运行状况统计","异常信息统计","配药用水量统计","总用水量统计","用电量统计","药剂使用情况统计"};
    public ReportFragmentAdapter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return imgs.length;
    }

    @Override
    public Object getItem(int position) {
        return imgs[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_gridview, null);
            holder = new ViewHolder(convertView);

            holder.ivIcon.setAdjustViewBounds(false);//设置边界对齐
            holder.ivIcon.setScaleType(ImageView.ScaleType.CENTER_CROP);//设置刻度的类型
            holder.ivIcon.setPadding(8, 8, 8, 8);//设置间距
            holder.ivIcon.setImageResource(imgs[position]);
            holder.tvTitle.setText(strings[position]);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.iv_icon)
        ImageView ivIcon;
        @Bind(R.id.tv_title)
        TextView tvTitle;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
